/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jskiller.map;

import java.util.ArrayList;
import java.lang.Math;
/**
 *
 * @author Administrator
 */
public class MapBlock {
    ArrayList<MapBlock> primes = new ArrayList();

    int x;
    int y;
    int w;
    int h;

    public void moveto(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int size() {
	return w * h;
    }

    public void locate(int x, int y) {
         this.x = x - (this.w/2);
         this.y = y - (this.h/2);

    }

    public void merge( MapBlock block){

        int i = Math.max(x+w, block.x+block.w);
        int j = Math.max(y+h, block.y+block.h);

        x = Math.min(x, block.x);
        y = Math.min(y, block.y);
        w = i-x;
        h = j-y;

    }

    public void scale(int dx, int dy){
        if (w + dx*2 > 0){
            w = w+dx*2;
            x = x-dx;
        }

        if (h + dy*2>0){
           h = h + dy*2;
           y = y - dy;
        }
    }
}
